#pragma once
#include "stdafx.h"
//-------------------------------------------------------------------------------------------------
//ImageProcStep.h  - Declaration of an Image Processing Step           
//-------------------------------------------------------------------------------------------------
//FreeBSD License
//Copyright 2012 Will Stott All rights reserved.
//
//Redistribution and use in source and binary forms, with or without modification, are
//permitted provided that the following conditions are met:
//
//   1. Redistributions of source code must retain the above copyright notice, this list of
//      conditions and the following disclaimer.
//
//   2. Redistributions in binary form must reproduce the above copyright notice, this list
//      of conditions and the following disclaimer in the documentation and/or other materials
//      provided with the distribution.
//
//THIS SOFTWARE IS PROVIDED BY Will Stott ``AS IS'' AND ANY EXPRESS OR IMPLIED
//WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
//FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL Will Stott OR
//CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
//CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
//SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
//ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
//NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
//ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//
//The views and conclusions contained in the software and documentation are those of the
//authors and should not be interpreted as representing official policies, either expressed
//or implied, of Will Stott.
//
//----Authors--------------------------------------------------------------------------------------
//created by: will.stott@ucl.ac.uk Feb 2012
//
//----Comments-------------------------------------------------------------------------------------
//
//-------------------------------------------------------------------------------------------------
#ifdef PLUGINICPROCSTEPS_EXPORTS
#define PLUGINICPROCSTEPS_API __declspec(dllexport)
#else
#define PLUGINICPROCSTEPS_API __declspec(dllimport)
#endif

#include "ImageExpt.h"
#include "ImageProcFn.h"
#include "ImageProcStepLibs.h"


class  PLUGINICPROCSTEPS_API ImageProcStep
{
public:
	static const char * const xmlProcStep;
	static const char * const attribStepAnalysis;
	static const char * const attribStepAnalysisYes;
	static const char * const attribStepNum;
	static const char * const attribLibName;
	static const char * const attribInterfaceVersion;
	static const char * const attribLibVersion;
	static const char * const attribFunctionName;

	static const char * const NoDescription;
	static const char * const NoResult;
	static const char * const NoScore;
	static const char * const InvalidIntermedImageFile;

	static const int	ImageProcStep::InvalidStepNum = -1;
	
public:
	ImageProcStep(void);
	ImageProcStep(ImageProcStep *step);
	ImageProcStep(TiXmlElement *processStep, ImageProcStepLibs *procLibs);
	ImageProcStep(int StepNo, IImageProcStepLibDyn *pLib, IImageProcFn *pFn, ProcParamsInputs *pInputs, ProcParamsOutputs *pOutputs);  //this makes a copy of inputs and outputs, but lib and fn are shared amongst all ImpageProcSteps as they are readonly

	virtual ~ImageProcStep(void);

	void			 SetIntermediateImagePathFilename(const char *pIntermedPathFilename) { ((pIntermedPathFilename != '\0') ? _IntermediateImagePathFilename = pIntermedPathFilename : _IntermediateImagePathFilename = ImageProcStep::InvalidIntermedImageFile); }

	bool			 Start(bool DebugMode);
	bool			 IsDone() { return false; }

	int					GetStepNum() { return _StepNo; }
	const char *		GetFunctionName() { return (_fn != '\0') ? _fn->GetFunctionName() : ImageProcFn::BadName; }
	const char *		GetString() { return _Description.c_str(); }
	ProcParamsInputs  *	GetInputs() { return _inputs; }
	ProcParamsOutputs *	GetOutputs() { return _outputs; }
	void				SetInputs(ProcParamsInputs  *inputs) { _inputs = inputs; }
	void				SetOutputs(ProcParamsOutputs *outputs) { _outputs = outputs; }
	const char *		GetResult();
	const char *		GetScore();

	const char *		GetIntermediateImagePathFilename() { return _IntermediateImagePathFilename.c_str(); }

	IImageProcStepLibDyn *GetLib() { return _lib; }
	ImageProcFn       *	GetFunction() { return _fn; }


	virtual bool	 IsValid()  { return (_error == false) ? true : false; }
	virtual bool	 Validate(); 
	virtual bool	 IsAnalysisStep() { return ((_fn != '\0') ? (_fn->IsAnalysisFn()) : false); }
	virtual bool	 SaveSettingsToXml(TiXmlElement *xmlProcSteps); 
	virtual bool	 SaveResultsToXml(TiXmlElement *image);

protected:
	ImageProcStep(int SeqNo);

	virtual bool	 LoadStep(TiXmlElement *stepXml, ImageProcStepLibs *procLibs);
	virtual bool	 InitialiseStep(TiXmlElement *stepXml, IImageProcStepLibDyn *DynLib);
	virtual void	 SetDescription();
protected:
	bool				_error;
	int					_StepNo;

private:
	IImageProcStepLibDyn *_lib;
	ImageProcFn       *	_fn;
	ProcParamsInputs  *	_inputs;
	ProcParamsOutputs *	_outputs;
#pragma warning(disable:4251)
	std::string         _Description;
	std::string			_IntermediateImagePathFilename;
#pragma warning(default:4251)

};


//-------------------------------------------------------------------------------------------------
//			E N D   O F   F I L E
//-------------------------------------------------------------------------------------------------
